package entity;


import java.util.ArrayList;
import java.util.List;

/**
     * 包含分页数据的对象Page
     * @param <T>
     */
    public class PageBean<T> {
        /**
         * 装填的集合数据
         */
        private List<T> list = new ArrayList<>();
        /**
         * 数据总条数
         */
        private Long total;
        /**
         * 当前页号
         */
        private int pageNum;
        /**
         * 每页大小
         */
        private int pageSize = 5;
        private Long pageTotal;

        public PageBean(){}

        public List<T> getList() {
            return list;
        }

        public void setList(List<T> list) {
            this.list = list;
        }

        public Long getTotal() {
            return total;
        }

        public void setTotal(Long total) {
            this.total = total;
        }

        public int getPageNum() {
            return pageNum;
        }

        public void setPageNum(int pageNum) {
            this.pageNum = pageNum;
        }

        public int getPageSize() {
            return pageSize;
        }

        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }
    public Long getPageTotal() {

        return pageTotal;
    }

    public void setPageTotal(Long total,int pageSize) {
        Long pageSize1=(long)pageSize;
        if (total%pageSize1==0)
            this.pageTotal = total/pageSize1;
        else
            this.pageTotal = total/pageSize1+1;

    }

    @Override
    public String toString() {
        return "PageBean{" +
                "list=" + list +
                ", total=" + total +
                ", pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", pageTotal=" + pageTotal +
                '}';
    }

        /**
         * getIsLastPage --- isLastPage
         * @return
         */
        public boolean getIsLastPage(){
         /*
         总页数：totalPage = total%pageSize==0?(total/pageSize) : (total/pageSize + 1)
             判断条件： pageNum >= totalPage  最后一页
              pageNum < totalPage 不是最后一页。
          */

            long totalPage = total % pageSize == 0?(total/pageSize) : (total/pageSize+1);
            return pageNum >= totalPage;
        }

}
